home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / canacces.os2 < prev    next >
Text File  |  1996-05-23  |  2KB  |  70 lines

  1. #line 2 "osdep/canacces.os2"
  2. /*----------------------------------------------------------------------
  3.        Check if we can access a file in a given way
  4.  
  5.    Args: file      -- The file to check
  6.          mode      -- The mode ala the access() system call, see ACCESS_EXISTS
  7.                       and friends in pine.h.
  8.  
  9.  Result: returns 0 if the user can access the file according to the mode,
  10.          -1 if he can't (and errno is set).
  11.  ----*/
  12. int
  13. can_access(file, mode)
  14.     char *file;
  15.     int   mode;
  16. {
  17.     return(access(file, mode));
  18. }
  19.  
  20.  
  21. /*----------------------------------------------------------------------
  22.        Check if we can access a file in a given way in the given path
  23.  
  24.    Args: path     -- The path to look for "file" in
  25.      file      -- The file to check
  26.          mode      -- The mode ala the access() system call, see ACCESS_EXISTS
  27.                       and friends in pine.h.
  28.  
  29.  Result: returns 0 if the user can access the file according to the mode,
  30.          -1 if he can't (and errno is set).
  31.  ----*/
  32. can_access_in_path(path, file, mode)
  33.     char *path, *file;
  34.     int   mode;
  35. {
  36.     char tmp[MAXPATH], *path_copy, *p, *t;
  37.     int  rv = -1;
  38.  
  39.     if(!path || !*path || file[1] == ':' || *file == '/' || *file == '\\'){
  40.     rv = access(file, mode);
  41.     }
  42.     else{
  43.     for(p = path_copy = cpystr(path); rv == -1 && p && *p; p = t){
  44.         if(t = strindex(p, ';'))
  45.           *t++ = '\0';
  46.  
  47.         sprintf(tmp, "%s\\%s", p, file);
  48.         /* For DOS/OS2 systems we may need to add a .EXE/.COM/.BAT
  49.            extension for executables */
  50.         if (mode == EXECUTE_ACCESS && strchr(file, '.')==NULL){
  51.             int i, l = strlen(tmp);
  52. #ifdef OS2
  53.         static char * exts[] = { ".exe", ".com", ".bat" };
  54. #else
  55.         static char * exts[] = { ".exe", ".com", ".cmd" };
  56. #endif
  57.         for (i = 0; rv == -1 && i < 3; i++) {
  58.             strcpy(tmp + l, exts[i]);
  59.             rv = access(tmp, mode);
  60.         }
  61.         }
  62.         else rv = access(tmp, mode);
  63.     }
  64.  
  65.     fs_give((void **)&path_copy);
  66.     }
  67.  
  68.     return(rv);
  69. }
  70.